#1参考知乎方差分析（ANOVA）在R语言中如何实现，csdn【R语言】数据标准化处理与b站教程

data<-read.csv("C:/Users/Rommel.Dks/Desktop/r/data.csv",row.names = 1)
data1=data[,-1]#处理数据，剔出第一列
data2 <- log2(data1)#对数处理合并
data2[data2 == -Inf] <- 0#设置inf，将-Inf的值替换
#分组
asym_list=grep('^(asym)',colnames(data2))
ctl_list=grep('^(ctl)',colnames(data2))
ad_list=grep('^(ad)',colnames(data2))
group=c(colnames(data2))

library(stringr)
group=c(colnames(data))
j=1
for (i in group){
  if(!is.na(str_extract(i, "^asym"))){
    i="asym"
  }
  else if(!is.na(str_extract(i, "^ad"))){
    i="ad"
  }
  else if(!is.na(str_extract(i, "^ctl"))){
    i="ctl"
  }
  group[j]=i
  j=j+1
}
group
#循环求p
result<-data.frame(ID=rownames(data2),pvalue=NA)

for (i in rownames(data2)){
  exp=data2[rownames(data2)==i,]
  if((sum(exp[asym_list]!=0)>=3)&(sum(exp[ctl_list]!=0)>=3)&(sum(exp[ad_list]!=0)>=3))
    {
    oneway.test(exp~group)
    pvalue=oneway.test(exp~group)$p.value 
    result[rownames(data2)==i,2] <- pvalue
  }
  else{
    result[rownames(data2)==i,2] <- NA
  }
}
#2借鉴于http://wefindbio.com/h-nd-288.html，https://blog.csdn.net/weixin_54004950/article/details/128614881等
BiocManager::install("org.Hs.eg.db")
BiocManager::install("HDO.db")
library(clusterProfiler)
library(org.Hs.eg.db)
load(volcano.RData)
genedata=prostat[which(prostat$P<0.05),]
geneid <- bitr(genedata$ID, fromType="SYMBOL",
               toType="ENTREZID", OrgDb='org.Hs.eg.db')

enall <- enrichGO(gene = DEG$ENTREZID,
                  OrgDb = org.Hs.eg.db,  
                  ont = "all", 
                  pAdjustMethod = "BH",  
                  pvalueCutoff =0.05,  
                  qvalueCutoff =0.05,  
                  readable = TRUE 
)
dotplot(object = enall,showCategory = 20，font.size = 5)
